package com.swj.modules.monitor.vo.server;


import com.swj.common.core.utils.BigDecimalUtil;
import com.swj.common.core.utils.date.DateUtil;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.management.ManagementFactory;
import java.util.Date;

//JVM相关信息
@Data
@NoArgsConstructor
public class Jvm {

    //当前JVM占用的内存总数(M)
    private double total;

    //JVM最大可用内存总数(M)
    private double max;

    //JVM空闲内存(M)
    private double free;

    //JDK版本
    private String version;

    //JDK路径
    private String home;

    public double getTotal() {
        return BigDecimalUtil.div(total, (1024 * 1024), 2);
    }

    public double getMax() {
        return BigDecimalUtil.div(max, (1024 * 1024), 2);
    }

    public double getFree() {
        return BigDecimalUtil.div(free, (1024 * 1024), 2);
    }

    public double getUsed() {
        return BigDecimalUtil.div(total - free, (1024 * 1024), 2);
    }

    public double getUsage() {
        return BigDecimalUtil.mul(BigDecimalUtil.div(total - free, total, 4), 100);
    }
    //获取JDK名称
    public String getName() {
        return ManagementFactory.getRuntimeMXBean().getVmName();
    }

    //JDK启动时间
    public String getStartTime() {
        return DateUtil.formatDateToStr(DateUtil.YYYY_MM_DD_HH_MM_SS, DateUtil.getServerStartDate());
    }

    //JDK运行时间
    public String getRunTime() {
        return DateUtil.getDateBetween(new Date(), DateUtil.getServerStartDate());
    }

    //运行参数
    public String getInputArgs() {
        return ManagementFactory.getRuntimeMXBean().getInputArguments().toString();
    }
}
